package com.ztp.pc.test2;

import java.awt.EventQueue;

import javax.swing.DropMode;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTable;

import com.ztp.lib.files.LocalExplorer;
import com.ztp.lib.files.DisplayableFile;
import com.ztp.pc.gui.fileview.FileIconAndNameCellRenderer;
import com.ztp.pc.gui.fileview.FilePanel;
import com.ztp.pc.gui.fileview.FileTableModel;

import javax.swing.JSplitPane;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import javax.swing.JLabel;

public class LocalFilePanelTest {

	private JFrame frame;
	private JTable table;
	private JSplitPane splitPane;
	private JPanel panel_bottom;
	private JButton btnNewButton;
	private JPanel panel_1;
	private JPanel panel_2;
	private JTextField textField;
	private JPanel panel_3;
	private JLabel lblNewLabel;
	private JTextField textField_1;
	private JButton btnNewButton_1;
	private JPanel panel_4;
	private JComboBox comboBox;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LocalFilePanelTest window = new LocalFilePanelTest();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public LocalFilePanelTest() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 595, 542);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout(0, 0));
		frame.getContentPane().add(panel, BorderLayout.CENTER);
		
		splitPane = new JSplitPane();
		splitPane.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentResized(ComponentEvent e) {
				splitPane.setDividerLocation(0.5);
			}
		});
		panel.add(splitPane, BorderLayout.CENTER);
		
		splitPane.setLeftComponent(new FilePanel(new LocalExplorer("E:\\")));
		
		panel_1 = new JPanel();
		splitPane.setRightComponent(panel_1);
		panel_1.setLayout(new BorderLayout(0, 0));
		
		panel_2 = new JPanel();
		panel_1.add(panel_2, BorderLayout.NORTH);
		panel_2.setLayout(new BorderLayout(0, 0));
		
		textField = new JTextField();
		panel_2.add(textField, BorderLayout.NORTH);
		textField.setColumns(10);
		
		panel_3 = new JPanel();
		panel_2.add(panel_3, BorderLayout.SOUTH);
		panel_3.setLayout(new BorderLayout(0, 0));
		
		lblNewLabel = new JLabel("New label");
		panel_3.add(lblNewLabel, BorderLayout.WEST);
		
		textField_1 = new JTextField();
		textField_1.getDocument().addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				System.out.println("removeUpdate " +e.toString());
				
			}
			
			@Override
			public void insertUpdate(DocumentEvent e) {
				System.out.println("insertUpdate " +e.toString());
				
			}
			
			@Override
			public void changedUpdate(DocumentEvent e) {
				System.out.println("changedUpdate " +e.toString());
				
			}
		});
		panel_3.add(textField_1);
		textField_1.setColumns(10);
		
		btnNewButton_1 = new JButton("New button");
		panel_3.add(btnNewButton_1, BorderLayout.EAST);
		
		panel_4 = new JPanel();
		panel_2.add(panel_4, BorderLayout.CENTER);
		
		comboBox = new JComboBox<DisplayableFile>();
		
		panel_4.add(comboBox);
		
		panel_bottom = new JPanel();
		panel.add(panel_bottom, BorderLayout.SOUTH);
		
		btnNewButton = new JButton("New button");
		panel_bottom.add(btnNewButton);
		
	}

	/*public static JTable createTable(){
		JTable table = new JTable(new FileTableModel(new LocalExplorer("/")));
		table.getColumnModel().getColumn(0).setCellRenderer(new FileIconAndNameCellRenderer());
		table.setDragEnabled(true);
		table.setDropMode(DropMode.INSERT_ROWS);
		table.setShowHorizontalLines(false);
		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				JTable table = (JTable) e.getSource();
				
			}
		});
		//table.setRowSelectionAllowed(true);
		//table.setCellSelectionEnabled(true);
		//table.setFocusable(true);
		table.setAutoCreateRowSorter(true);
		return table;
	}*/
}
